package com.huawei.appgallery.forum.forum.forumletters.view;

import android.os.Build.VERSION;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import androidx.annotation.Nullable;
import com.huawei.appgallery.forum.base.https.jgw.JGWTabDetailResponse;
import com.huawei.appgallery.forum.base.ui.JGWTabFragment;
import com.huawei.appgallery.forum.forum.bean.ForumSectionInfoCardBean;
import com.huawei.appgallery.forum.forum.forumletters.widget.ForumLetterAdapter;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse.LayoutData;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.hmf.annotation.FragmentDefine;
import huawei.widget.HwAlphaIndexerListView;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import o.azb;
import o.bsl;
import o.bun.c;
import o.bun.d;
import o.buz;
import o.ContentManager;
import o.CollectCheck;
import o.fpq;
import o.fpr;
import o.fps;

@FragmentDefine(alias = "forum_letter_frg", protocol = IForumLetterFrgProtocol.class)
public class ForumLetterFragment extends JGWTabFragment {
    private HwAlphaIndexerListView ʻˊ;
    private List<ForumSectionInfoCardBean> ʻˋ;
    private View ʼˋ;
    private List<Map<String, Object>> ꜞॱ = new ArrayList();
    private ListView ꞌॱ;
    private fps ﹳॱ;
    Map<String, String> ﾞ = new LinkedHashMap();

    public void ˏ(@Nullable Bundle bundle) {
        this.ʼ = new bsl(this, null, ((IForumLetterFrgProtocol) this.ﹳ.ॱ()).getUri());
        super.ˏ(bundle);
    }

    public int ߵ() {
        return d.ͺ;
    }

    public void ˋ(ViewGroup viewGroup, LayoutInflater layoutInflater) {
        super.ˋ(viewGroup, layoutInflater);
        this.ʻˊ = (HwAlphaIndexerListView) viewGroup.findViewById(c.ॱ);
        azb.ॱॱ(this.ʻˊ, azb.ʽ(ContentManager.getInstant().getContext()));
        this.ꞌॱ = (ListView) viewGroup.findViewById(c.ᐨ);
        this.ʼˋ = viewGroup.findViewById(c.ॱʻ);
    }

    public boolean ˊ(TaskFragment taskFragment, b bVar) {
        boolean ˊ = super.ˊ(taskFragment, bVar);
        if (ʼʼ() != null) {
            ʼʼ().ˋ(taskFragment, bVar);
        }
        if (bVar.ˋ.getResponseCode() == 0 && bVar.ˋ.getRtnCode_() == 0 && (bVar.ˋ instanceof JGWTabDetailResponse)) {
            ˊ((JGWTabDetailResponse) bVar.ˋ);
            ॱˑ();
        }
        return ˊ;
    }

    private void ॱʾ() {
        this.ʼˋ.setVisibility(0);
    }

    private void ˊ(JGWTabDetailResponse jGWTabDetailResponse) {
        List<LayoutData> ᐝॱ = jGWTabDetailResponse.ᐝॱ();
        if (ᐝॱ != null && ᐝॱ.size() > 0) {
            for (LayoutData layoutData : ᐝॱ) {
                if ("forumsectioninfocard".equals(layoutData.ˏ()) && layoutData.ˋ().size() != 0) {
                    this.ʻˋ = layoutData.ˋ();
                    return;
                }
            }
        }
    }

    private void ॱˑ() {
        this.ߵ.setVisibility(8);
        if (!CollectCheck.isEmpty(this.ʻˋ)) {
            ॱʾ();
            for (ForumSectionInfoCardBean forumSectionInfoCardBean : this.ʻˋ) {
                forumSectionInfoCardBean.ˏ(ˋॱ(forumSectionInfoCardBean.ˊ().ˏ()));
            }
            this.ﾞ.clear();
            ॱـ();
            ॱˉ();
        }
    }

    private String ˋॱ(String str) {
        fpq ˎ = fpq.ˎ();
        if (VERSION.SDK_INT >= 24) {
            return TextUtils.isEmpty(str) ? "" : ˎ.ˋ(str);
        } else {
            return ॱˊ(str.substring(0, 1));
        }
    }

    private String ॱˊ(String str) {
        String ˋ = fpr.ˏ().ˋ(str);
        return ˋ != null ? ˋ.substring(0, 1).toUpperCase(Locale.ENGLISH) : "";
    }

    private void ॱˉ() {
        boolean z = false;
        if (this.ꞌॱ != null) {
            this.ꞌॱ.setAdapter(new ForumLetterAdapter(ॱˋ(), this.ꜞॱ, "sort_key", false));
            HwAlphaIndexerListView hwAlphaIndexerListView = this.ʻˊ;
            if (ᐝॱ().getConfiguration().orientation == 2) {
                z = true;
            }
            hwAlphaIndexerListView.ॱ(z, true);
            this.ﹳॱ = new fps(this.ꞌॱ, this.ʻˊ);
            this.ﹳॱ.ˊ();
        }
    }

    private void ॱـ() {
        if (this.ʻˋ.size() != 0) {
            Map hashMap = new HashMap();
            buz o_buz = new buz();
            ForumSectionInfoCardBean forumSectionInfoCardBean = (ForumSectionInfoCardBean) this.ʻˋ.get(0);
            String ʽ = forumSectionInfoCardBean.ʽ();
            o_buz.ॱ(ʽ);
            o_buz.ˊ(forumSectionInfoCardBean);
            this.ʻˋ.remove(0);
            if (this.ʻˋ.size() == 0) {
                ˋ(o_buz);
                hashMap.put("sort_key", o_buz);
                this.ꜞॱ.add(hashMap);
                return;
            }
            Iterator it = this.ʻˋ.iterator();
            while (it.hasNext()) {
                forumSectionInfoCardBean = (ForumSectionInfoCardBean) it.next();
                Object ʽ2 = forumSectionInfoCardBean.ʽ();
                if (!TextUtils.isEmpty(ʽ2) && ʽ2.equals(ʽ)) {
                    o_buz.ˏ(forumSectionInfoCardBean);
                    it.remove();
                    break;
                }
            }
            ˋ(o_buz);
            hashMap.put("sort_key", o_buz);
            this.ꜞॱ.add(hashMap);
            ॱـ();
        }
    }

    private void ˋ(buz o_buz) {
        if (!this.ﾞ.containsKey(o_buz.ˊ())) {
            this.ﾞ.put(o_buz.ˊ(), o_buz.ˎ().ˊ().ˏ());
        }
        o_buz.ˎ((String) this.ﾞ.get(o_buz.ˊ()));
    }
}
